package com.life.goal.application.service;

import com.life.goal.application.dto.request.LoginRequest;
import com.life.goal.domain.entity.User;
import com.life.goal.domain.support.UserRepository;
import com.life.goal.infrastructure.exception.UserBizException;
import com.life.goal.infrastructure.exception.UserErrorCodeEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserService {

    @Resource
    private UserRepository userRepository;

    /**
     * 登录方法
     */
    public User login(LoginRequest request) {
        User user = userRepository.findUserByNameAndPwd(request.getName(), request.getPassword());
        if (user == null) {
            throw new UserBizException(UserErrorCodeEnum.USER_PASSWORD_NOT_RIGHT);
        }
        return user;
    }
}
